<template>
  <div>
    <!-- 顶部导航条  -->
    <div id="slider" class="mui-slider">
      <div
        id="sliderSegmentedControl"
        class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted"
      >
        <div class="mui-scroll">
          <a :class="['mui-control-item', item.id == 0 ? 'mui-active' : '']" 
            v-for="item in topBarList" :key="item.id" @click="getImgList(item.id)"
          >
            {{ item.title }}
          </a>
        </div>
      </div>
    </div>

    <!-- 图片列表 -->
    <ul class="imglist-ul">
      <router-link v-for="item in imglist" :key="item.id" tag="li" :to="'/home/photoInfo/' + item.id" >
        <img v-lazy="item.img_url">
        <div class="img-info">
          <h2>{{ item.title }}</h2>
          <p>{{ item.content }}</p>
        </div> 
      </router-link>
    </ul>
  </div>
</template>
<script>
import mui from "../../lib/mui/js/mui.min.js";
export default {
  data() {
    return {
      topBarList: [],
      imglist: []
    };
  },
  mounted() {
    //页面第一次渲染完后执行
    //实现头部导航栏滚动
    mui(".mui-scroll-wrapper").scroll({
      deceleration: 0.0005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
    });
  },
  created() {
    this.getTopTabbarList();

    this.getImgList(0);
  },
  methods: {
    getTopTabbarList() {
      this.$http.get('./../../../api/phototobbar.json').then(res => {
        if(res.body.status === 0) {
          this.topBarList = res.body.message;
        }else {
          alert('error');
        }
      })
    },
    getImgList(tobbarid) {
      //this.$http.get('图片列表接口/' + tobbarid).then(res => {
      this.$http.get('./../../../api/homephotoimglist.json').then(res => {
        if(res.body.status === 0) {
          this.imglist = res.body.message;
        }else {
          alert('error');
        }
      })
    }
  }
};
</script>
<style scoped>
  /* 消除谷歌滚动警告 */
  * {
    touch-action: pan-y;
  }

  .mui-slider {
    position: fixed;
    background-color: #fff
  }
  img{
    width: 100%;
    vertical-align: middle;
   }

  img[lazy=loading] {
    width: 40px;
    height: 300px;
    margin: auto;
  }

  .imglist-ul {
    padding: 0 10px;
    margin: 0;
    padding-bottom: 0;
  }

  .imglist-ul li {
    list-style: none;
    background-color: #ccc;
    margin-bottom: 10px;
    position: relative;
    box-shadow:  0 0 9px #999;
  }
  .img-info {
    color: white;
    background-color: rgba(0, 0, 0, 0.4);
    position: absolute;
    bottom: 0;
    opacity: 0.8;
    max-height: 80px;
  }
  .img-info h2 {
    font-size: 14px;
  }

  .img-info p {
    font-size: 13px;
    color: white;
  }
</style>
